define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'jdy/heyue/index',
                    add_url: 'jdy/heyue/add',
                    edit_url: 'jdy/heyue/edit',
                    del_url: 'jdy/heyue/del',
                    multi_url: 'jdy/heyue/multi',
                    table: 'jdy_heyue',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                showToggle: false,
                showColumns: true,
                showExport: false,
                searchFormVisible: true,
                columns: [
                    [
                        //{checkbox: true},
                        {field: 'id', title: __('Id'), operate: false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate},
                        {field: 'anchang.name', title: __('Anchang.name'), operate: false},
                        //{field: 'anchang_id', title: __('Anchang_id')},
                        {field: 'contract_no', title: __('Contract_no'), operate: false},
                        {field: 'remind_start_date', title: __('Remind_start_date'), operate:false, addclass:'datetimerange'},
                        {field: 'remind_end_date', title: __('Remind_end_date'), operate:false, addclass:'datetimerange'},
                        {field: 'service_cycle', title: __('Service_cycle'), operate:false, searchList: {"周":__('周'),"月":__('月'),"季":__('季')}, formatter: Table.api.formatter.normal},
                        {field: 'times', title: __('Times'), operate: false},
                        {field: 'mans', title: __('Mans'), operate: false},
                        {field: 'service_hours', title: __('Service_hours'), operate:false, searchList: {"0":__('Service_hours 0')}, formatter: Table.api.formatter.normal},
                        {field: 'fee', title: __('Fee'), operate:false},
                        {field: 'tax', title: __('Tax'), operate:false, searchList: {"不含稅":__('不含稅'),"含稅":__('含稅')}, formatter: Table.api.formatter.normal},
                        {field: 'fee_cycle', title: __('Fee_cycle'), operate:false, searchList: {"月繳":__('月繳'),"季繳":__('季繳'),"半年繳":__('半年繳'),"年繳":__('年繳')}, formatter: Table.api.formatter.normal},
                        {field: 'contract_status', title: __('Contract_status'), operate:false, searchList: {"生效":__('生效'),"中止":__('中止')}, formatter: Table.api.formatter.status},
                        //{field: 'files', title: __('文件'), events: Table.api.events.file, formatter: Table.api.formatter.files, operate:false},
                        {field: 'luruman', title: __('Luruman'), operate:false},
                        //{field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'update_time', title: __('Update_time'), operate:false, operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'anchang.id', title: __('Anchang.id')},
                        //{field: 'anchang.building_id', title: __('Anchang.building_id')},
                        //{field: 'anchang.room_id', title: __('Anchang.room_id')},
                        //{field: 'anchang.name', title: __('Anchang.name')},
                        //{field: 'anchang.type', title: __('Anchang.type')},
                        //{field: 'anchang.addr', title: __('Anchang.addr')},
                        //{field: 'anchang.remark', title: __('Anchang.remark')},
                        //{field: 'anchang.floor_no', title: __('Anchang.floor_no')},
                        //{field: 'anchang.contact1_id', title: __('Anchang.contact1_id')},
                        //{field: 'anchang.contact2_id', title: __('Anchang.contact2_id')},
                        //{field: 'anchang.companywindow_id', title: __('Anchang.companywindow_id')},
                        //{field: 'anchang.xianshi', title: __('Anchang.xianshi')},
                        //{field: 'anchang.xzq', title: __('Anchang.xzq')},
                        //{field: 'anchang.mapurl', title: __('Anchang.mapurl'), formatter: Table.api.formatter.url},
                        //{field: 'anchang.orderdate', title: __('Anchang.orderdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'anchang.fee', title: __('Anchang.fee')},
                        //{field: 'anchang.fee_type', title: __('Anchang.fee_type')},
                        //{field: 'anchang.pay_date', title: __('Anchang.pay_date'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'anchang.is_pay', title: __('Anchang.is_pay')},
                        //{field: 'anchang.create_time', title: __('Anchang.create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'anchang.update_time', title: __('Anchang.update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'anchang.contact1_name', title: __('Anchang.contact1_name')},
                        //{field: 'anchang.contact1_mobile', title: __('Anchang.contact1_mobile')},
                        //{field: 'anchang.contact2_name', title: __('Anchang.contact2_name')},
                        //{field: 'anchang.contact2_mobile', title: __('Anchang.contact2_mobile')},

                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});